import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.LinkedList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;


public class LoggedInFrame extends JFrame{
    static LinkedList<String> filmImagesList;
    static Connection theConnection;
    static ArrayList<JButton> buttons = new ArrayList() ;
    static ArrayList<String> filmHyperlinks = new ArrayList();
    JButton blogin = new JButton("Member Login");
    JButton blogOut = new JButton("Log Out");
    JButton loggedInUserName;
    BrowserButton panel;


    LoggedInFrame( String userName ){
        Image bGround = ReadImage.getImage("http://wallpapers.wallbase.cc/rozne/wallpaper-389121.jpg");
        Browser bGPanel = new Browser( bGround );
        add(bGPanel);

        loggedInUserName = new JButton( "Currently logged in as " + userName );

        int xPos = 20;
        int yPos = 50;

        for( String link : ImageInJFrame.filmImagesList ){
            Image filmImage = ReadImage.getImage( link );
            panel = new BrowserButton( filmImage );
            buttons.add( panel );
            filmHyperlinks.add(link);
            panel.setBounds(xPos, yPos, 130, 200);
            bGPanel.add(panel);
            xPos = xPos +250;
        }

        for( int i=0; i< buttons.size(); i++){
            buttons.get(i).setActionCommand( filmHyperlinks.get(i) );
            buttons.get(i).addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                    String hyperlink = e.getActionCommand();
                    String filmDetails = Film.getFilm( hyperlink );
                    FilmDetailsFrame filmInfo = new FilmDetailsFrame( hyperlink, filmDetails );
                }
            });
        }

        loggedInUserName.setBounds(50,10,250,20);
        blogin.setBounds(1150,10,130,20);
        blogOut.setBounds(1300,10,100,20);
        bGPanel.add(blogin);
        bGPanel.add(loggedInUserName);
        bGPanel.add(blogOut);

        setVisible(true);
        setSize(1440,850);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        clickLogin();
    }

    public void clickLogin(){
        blogin.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent ae ){
                if( ImageInJFrame.loggedIn == false ){
                    Login loginFrame = new Login();
                    loginFrame.setVisible( true );
                }else{
                    JOptionPane.showMessageDialog( null, "Please log out first" );
                }
            }
        });
    }
}

